package 力扣日常刷题.木22一月.第07天0115;

/**
 * @author 帅小伙
 * @date 2022/1/15
 * @description
 * 题解 https://leetcode-cn.com/problems/stone-game/solution/shi-zi-you-xi-dong-tai-gui-hua-qu-jian-d-5ra8/
 */
public class Demo09动态规划石子游戏 {


    public boolean stoneGame(int[] piles) {
        int n = piles.length;
        if(n == 0) return false;
        int[][] dp = new int[n][n];
        for (int i = 0; i < n; i++) {
            dp[i][i] = piles[i];
        }
        for (int i = n-1; i >=0 ; i--) {
            for (int j = i+1; j < n; j++) {
                dp[i][j] = Math.max(piles[i] - dp[i+1][j],piles[j] - dp[i][j-1]);
            }
        }
        return dp[0][n-1] > 0;
    }

}
